<!-- 业务列表 -->
<template>
	<view v-for="item in listData" style="padding: 10px;">
		<uni-card :is-shadow="false" padding="0" spacing="0" margin="0">
			<navigator :url="'/pages/bspsd/business/details?detailsData=' + JSON.stringify(item)" hover-class="none">
				<uni-list :border="false">
					<uni-list-item title="业务编号" :rightText="item.ywbh + ''" />
					<uni-list-item title="业务类型" :rightText="getywlbText(item.ywlb)" />
					<uni-list-item title="当前进度" :rightText="item.xmjl" />
					<uni-list-item title="申请时间" :rightText="item.sqrq + ''" />
				</uni-list>
			</navigator>
			<!-- <view slot="actions">
        <uni-row>
          <uni-col :span="12">
            <navigator :url="'/pages/bspsd/business/details?detailsData=' + JSON.stringify(item)" hover-class="none">
              <view class="item-btn item-btn2">详细</view>
            </navigator>
          </uni-col>
          <uni-col :span="12">
            <view class="item-btn item-btn3" @click="cancelClick(item)">取消业务办理</view>
          </uni-col>
        </uni-row>
      </view> -->
		</uni-card>
	</view>
	<cNoData v-if="listData.length < 1" />
</template>

<script setup lang="ts">
	import cNoData from "@/pages/bspsd/components/no-data.vue";
	import { getPhone } from "@/utils/storage";
	import { businessList } from "@/api/request/businessList"
	import { businessCancel } from "@/api/request/businessCancel"
	import { SysZfdmQuery } from "@/api/request/SysZfdmQuery";
	import { getSysZfdm } from "@/api/syszfdm"
	import { SysZfdm } from "@/api/tables/SysZfdm"
	import { YhYwJbxx } from "@/api/tables/YhYwJbxx";
	import { ref } from "vue"
	import { onShow } from '@dcloudio/uni-app'

	const listData = ref<Array<YhYwJbxx>>([])
	const YWLBLIST = ref<Array<SysZfdm>>([])

	onShow(() => {
		getListData()
		SysZfdmQuery({
			data: { zfdm: { dmzl: "YWLB" } },
			success: (result) => {
				let list = result || []
				YWLBLIST.value = list
			}
		})
		// getSysZfdm({
		// 	dmzl: "YWLB",
		// 	success: (result) => {
		// 		YWLBLIST.value = result
		// 	}
		// })
	})
	const getywlbText = (ywlb : String) => {
		for (let k of YWLBLIST.value) {
			if (k.dmbh == ywlb) {
				return k.dmnr
			}
		}
		return ''
	}
	function getListData() {
		businessList({
			data: {
				lxsj: getPhone()
			},
			success: (res : YhYwJbxx[]) => {
				listData.value = res
			},
			fail: (_code, message) => {
				uni.showModal({ content: "查询用户在办业务信息失败，" + message, showCancel: false })
			}
		})
	}

	function cancelClick(item : YhYwJbxx) {
		uni.showModal({
			title: '提示',
			content: '是否确定取消此业务',
			success: function (res) {
				if (res.confirm) {
					businessCancel({
						data: {
							jbxx: item
						},
						success: () => {
							uni.showToast({ icon: "success", title: '取消成功' })
							getListData()
						},
						fail: (_code, message) => {
							console.log(message)
							uni.showModal({ title: '提示', content: "业务取消失败，请稍后重试", showCancel: false })
						}
					})
				}
			}
		});
	}
</script>

<style lang="scss" scoped>
	.item-btn {
		color: #fff;
		text-align: center;
		font-size: 24rpx;
		line-height: 80rpx;
	}

	.item-btn2 {
		background-color: #f3a73f;
		border-color: #f3a73f;
	}

	.item-btn3 {
		background-color: #e43d33;
		border-color: #e43d33;
	}
</style>